package com.java.example.ui.activity

import android.content.Intent
import android.media.RingtoneManager
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import com.java.example.util.StatusBarUtil
import com.java.example.BuildConfig
import com.java.example.R
import com.java.example.base.BaseActivity
import com.java.example.databinding.ActivityLoginBinding
import com.java.example.ui.viewmodel.LoginViewModel

class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login) {
    private val viewModel: LoginViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarUtil.setTransparentForWindow(this)
        StatusBarUtil.setDarkMode(this)
        viewModel.binding = binding
        binding.click = Clickable()
        binding.viewModle = viewModel
        binding.lifecycleOwner = this
        viewModel.gotoMain = ::gotoMain
        if (intent.getBooleanExtra("isShowBack", false)) {
            binding.ivBack.visibility = View.VISIBLE
        } else {
            binding.ivBack.visibility = View.GONE
        }
        if (BuildConfig.DEBUG) {
            test()
        }
        viewModel.phone.observe(this) { str ->

        }
    }

    private fun gotoMain() {
        //播放提示音
        val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
        val r = RingtoneManager.getRingtone(applicationContext, notification)
        r.play()
        startActivity(Intent(this@LoginActivity, MainActivity::class.java))
        finishAffinity()
    }

    private fun test() {
        viewModel.phone.value = "15566668803"
        viewModel.password.value = "123456"
        viewModel.checked.value = true
    }

    inner class Clickable : ClickableBase() {
        fun register() {
//            startActivity(Intent(this@LoginActivity, RegisterActivity::class.java))
//            overridePendingTransition(R.anim.push_bottom_in, R.anim.push_bottom_out)
        }
    }
}
